/**
 * @description 链接用户 API
 * @date 2020-07-14 15:14
 * @author LI
 */

const router = require('koa-router')()
const {
  getDeductionRecords,
  AddShopAddress,
  getUserShopAddress,
  updateShopName
} = require('../../controller/linkUser')

router.prefix('/jihuide/linkUser')

// 链接用户查看扣款记录
router.get('/getDeductionRecords', async (ctx, next) => {
  let { startTime, endTime, page, limit } = ctx.request.query
  page = parseInt(page)
  limit = parseInt(limit)
  const result = await getDeductionRecords({
    ctx,
    startTime,
    endTime,
    page,
    limit,
  })

  ctx.body = result
})

// 链接用户添加店铺地址
router.post('/AddShopAddress', async (ctx, next) => {
  let { id, companyAddress } = ctx.request.body
  id = parseInt(id)
  const result = await AddShopAddress(id, companyAddress)

  ctx.body = result
})

// 链接用户获取店铺地址
router.post('/getUserShopAddress', async (ctx, next) => {
  let { id } = ctx.request.body
  id = parseInt(id)
  const result = await getUserShopAddress(id)

  ctx.body = result
})

// 修改店铺名称
router.post('/updateShopName', async (ctx, next) => {
  let { id, name } = ctx.request.body
  id = parseInt(id)
  const result = await updateShopName(id, name)

  ctx.body = result
})

module.exports = router
